-- local count = 0;
-- for k, v in NWB:pairsByKeys(NWB.data.layers) do
--     count = count + 1;
--     if (k == tonumber(zoneID)) then
--         NWBlayerFrame.fs2:SetText("|cFF9CD6DE" .. L["You are currently on"] .. " |cff00ff00[Layer " .. count .. "]|cFF9CD6DE.|r");
--         if (NWB.currentLayerShared ~= count) then
--             NWB:sendL(count, "set current layer text");
--             NWB.currentLayerShared = count;
--         end


-- local topCenter = C_UIWidgetManager.GetTopCenterWidgetSetID()
-- local widgets = C_UIWidgetManager.GetAllWidgetsBySetID(topCenter)
-- local text = ""
-- for _, w in pairs(widgets) do
--     print(w.widgetID)

--     print( C_UIWidgetManager.GetIconAndTextWidgetVisualizationInfo(3097).text )

--     if w.widgetID == 3119 then
--         print(C_UIWidgetManager.GetIconAndTextWidgetVisualizationInfo(3119).text)
--         text = C_UIWidgetManager.GetIconAndTextWidgetVisualizationInfo(3119).text
--     end

-- end


-- local MinimapLayerFrame = CreateFrame("Frame", "MinimapLayerFrame", Minimap, "ThinGoldEdgeTemplate");
-- MinimapLayerFrame:SetPoint("TOP", 8, 4);
-- MinimapLayerFrame:SetFrameStrata("HIGH");
-- MinimapLayerFrame:SetFrameLevel(9);
-- MinimapLayerFrame:SetMovable(true);
-- MinimapLayerFrame.fs = MinimapLayerFrame:CreateFontString("MinimapLayerFrameFS", "ARTWORK");
-- MinimapLayerFrame.fs:SetPoint("CENTER", 0, 0);
-- MinimapLayerFrame.fs:SetFont("Fonts\\ARIALN.ttf", 8);

-- local timeStr = select(3,strsplit(" ", text))
-- MinimapLayerFrame.fs:SetText( timeStr );








local gui = nil
function OpenGUI()
	if gui then gui:Show() return end

	-- Main Frame
	gui = CreateFrame("Frame", "NDuiPlusGUI", UIParent)
	tinsert(UISpecialFrames, "NDuiPlusGUI")
	gui:SetSize(600, 480)
	gui:SetPoint("CENTER")
	gui:SetFrameStrata("HIGH")
	gui:SetFrameLevel(10)
	B.CreateMF(gui)
	B.SetBD(gui)
	B.CreateFS(gui, 18, "NDui_Plus", true, "TOP", 0, -10)
	B.CreateFS(gui, 16, format("v%s", P.Version), false, "TOP", 0, -30)

	local close = P.CreateButton(gui, 80, 20, CLOSE)
	close:SetPoint("BOTTOMRIGHT", -20, 15)
	close:SetScript("OnClick", function() gui:Hide() end)

	local ok = P.CreateButton(gui, 80, 20, OKAY)
	ok:SetPoint("RIGHT", close, "LEFT", -5, 0)
	ok:SetScript("OnClick", function()
		gui:Hide()
		StaticPopup_Show("RELOAD_NDUI")
	end)

	for i, name in pairs(G.TabList) do
		guiTab[i] = CreateTab(gui, i, name)

		guiPage[i] = CreateFrame("ScrollFrame", nil, gui, "UIPanelScrollFrameTemplate")
		guiPage[i]:SetPoint("TOPLEFT", 110, -50)
		guiPage[i]:SetPoint("BOTTOMRIGHT", -30, 50)
		B.CreateBDFrame(guiPage[i], .25)
		guiPage[i]:Hide()
		guiPage[i].child = CreateFrame("Frame", nil, guiPage[i])
		guiPage[i].child:SetSize(guiPage[i]:GetWidth(), 1)
		guiPage[i]:SetScrollChild(guiPage[i].child)
		B.ReskinScroll(guiPage[i].ScrollBar)
		guiPage[i]:SetScript("OnMouseWheel", scrollBarHook)

		CreateOption(i)
	end

	local helpInfo = B.CreateHelpInfo(gui)
	helpInfo:SetPoint("TOPRIGHT", -10, -5)
	helpInfo.title = L["Changelog"]
	B.AddTooltip(helpInfo, "ANCHOR_RIGHT", L["Option Tips"], "info")
	helpInfo:SetScript("OnClick", setupChangelog)

	local credit = CreateFrame("Button", nil, gui)
	credit:SetPoint("TOPRIGHT", -50, -5)
	credit:SetSize(40, 40)
	credit.Icon = credit:CreateTexture(nil, "ARTWORK")
	credit.Icon:SetAllPoints()
	credit.Icon:SetTexture(DB.creditTex)
	credit:SetHighlightTexture(DB.creditTex)
	credit.title = "Credits"
	B.AddTooltip(credit, "ANCHOR_RIGHT", "|n"..GetAddOnMetadata(addonName, "X-Credits"), "info")

	local toggle = G.CreateToggleButton(gui)
	toggle:SetPoint("TOPLEFT", 25, -5)
	B.AddTooltip(toggle, "ANCHOR_RIGHT", "NDui", "info")
	toggle:SetScript("OnClick", function()
		if _G.GameMenuFrameNDui then
			_G.GameMenuFrameNDui:Click()
			gui:Hide()
		end
	end)

	if not NDuiPlusDB["Changelog"].Version or NDuiPlusDB["Changelog"].Version ~= P.Version then
		setupChangelog()
		NDuiPlusDB["Changelog"].Version = P.Version
	end

	local function showLater(event)
		if event == "PLAYER_REGEN_DISABLED" then
			if gui:IsShown() then
				gui:Hide()
				B:RegisterEvent("PLAYER_REGEN_ENABLED", showLater)
			end
		else
			gui:Show()
			B:UnregisterEvent(event, showLater)
		end
	end
	B:RegisterEvent("PLAYER_REGEN_DISABLED", showLater)

	SelectTab(1)
end















-- 使用 OnUpdate 创建一个迷你计时器
-- local total = 0
-- local function onUpdate(self,elapsed)
--     total = total + elapsed
--     if total >= 2 then
--         DEFAULT_CHAT_FRAME:AddMessage("ping!")
--         total = 0
--     end
-- end
-- local f = CreateFrame("frame")
-- f:SetScript("OnUpdate", onUpdate)





-- MyFrame = CreateFrame("Frame")
-- MyFrame:ClearAllPoints()
-- -- MyFrame:SetBackdrop(StaticPopup1:GetBackdrop())
-- MyFrame:SetHeight(300)
-- MyFrame:SetWidth(300)
-- MyFrame.text = MyFrame:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
-- MyFrame.text:SetAllPoints()
-- MyFrame.text:SetText("YOUR HELP TEXT HERE")
-- MyFrame:SetPoint("CENTER", 0, 0)





-- function SetActiveInactive(frame, active, inactive)
--     frame:SetScript("OnUpdate", function(self, elapsed)
--           local current = GetMouseFocus()
          
--           -- Scan through the parent chain
--           while current ~= nil do
--              if current == frame then
--                 frame:SetAlpha(active)
--                 return
--              end
             
--              current = current:GetParent()
--           end
          
--           frame:SetAlpha(inactive)
--     end)     
--  end
 
--  SetActiveInactive(MyFrame, 1.0, 0.7)




-- function DecimalToHex(r,g,b)
--     return string.format("|cff%02x%02x%02x", r*255, g*255, b*255)
-- end



-- local MOD_TextFrame = CreateFrame("Frame");
-- MOD_TextFrame:ClearAllPoints();
-- MOD_TextFrame:SetHeight(300);
-- MOD_TextFrame:SetWidth(300);
-- MOD_TextFrame:Hide();
-- MOD_TextFrame.text = MOD_TextFrame:CreateFontString(nil, "BACKGROUND", "PVPInfoTextFont");
-- MOD_TextFrame.text:SetAllPoints();
-- MOD_TextFrame:SetPoint("CENTER", 0, 200);
-- MOD_TextFrame:SetScript("OnUpdate", MOD_TextFrame_OnUpdate);

-- MOD_TextFrameTime = 0;
-- function MOD_TextFrame_OnUpdate()
--   if (MOD_TextFrameTime < GetTime() - 3) then
--     local alpha = MOD_TextFrame:GetAlpha();
--     if (alpha ~= 0) then MOD_TextFrame:SetAlpha(alpha - .05); end
--     if (alpha == 0) then MOD_TextFrame:Hide(); end
--   end
-- end

-- function MOD_TextMessage(message)
--   MOD_TextFrame.text:SetText(message);
--   MOD_TextFrame:SetAlpha(1);
--   MOD_TextFrame:Show();
--   MOD_TextFrameTime = GetTime();
-- end
-- MOD_TextMessage(123456)




-- MyStatusBar = CreateFrame("StatusBar", nil, UIParent)
-- MyStatusBar:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
-- MyStatusBar:GetStatusBarTexture():SetHorizTile(false)
-- MyStatusBar:SetMinMaxValues(0, 100)
-- MyStatusBar:SetValue(100)
-- MyStatusBar:SetWidth(200)
-- MyStatusBar:SetHeight(10)
-- MyStatusBar:SetPoint("CENTER",UIParent,"CENTER")
-- MyStatusBar:SetStatusBarColor(0,1,0)